﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace PSE.Updater.Common.Gateway
{
    /// <summary>
    /// Configuração de Comunicação entre Servidor e Client
    /// </summary>
    public class BindingFactory
    {
        /// <summary>
        /// Cria o NetTcpBinding
        /// </summary>
        /// <param name="tm">Tipo de Tranferência</param>
        /// <returns>NetTcpBinding</returns>
        public static NetTcpBinding CreateNetTcpBinding(TransferMode tm)
        {
            int value = 2147483647;

            NetTcpBinding binding = new NetTcpBinding();
            binding.Security.Mode = SecurityMode.None;
            binding.TransferMode = tm;
            binding.SendTimeout = new TimeSpan(0, 10, 0);
            binding.OpenTimeout = new TimeSpan(0, 10, 0);
            binding.CloseTimeout = new TimeSpan(0, 10, 0);
            binding.ReceiveTimeout = new TimeSpan(0, 10, 0);

            binding.MaxBufferPoolSize = value;
            binding.MaxBufferSize = value;
            binding.ReaderQuotas.MaxArrayLength = value;
            binding.MaxReceivedMessageSize = value;

            return binding;
        }

        public static NetNamedPipeBinding CreateNetNamedPipeBinding(TransferMode tm)
        {
            int value = 2147483647;

            NetNamedPipeBinding binding = new NetNamedPipeBinding();
            binding.Security.Mode = NetNamedPipeSecurityMode.None;
            binding.TransferMode = tm;
            binding.SendTimeout = new TimeSpan(0, 10, 0);
            binding.OpenTimeout = new TimeSpan(0, 10, 0);
            binding.CloseTimeout = new TimeSpan(0, 10, 0);
            binding.ReceiveTimeout = new TimeSpan(0, 10, 0);

            binding.MaxBufferPoolSize = value;
            binding.MaxBufferSize = value;
            binding.ReaderQuotas.MaxArrayLength = value;
            binding.MaxReceivedMessageSize = value;

            return binding;        
        }
    }
}
